﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;

namespace zielonka.co.uk.extensions.system.drawing
{
    // Description:	Convert an image to a memory stream
    /*
        Image image = ...;
        MemoryStream stream = image.ToMemoryStream(ImageFormat.Png);
     */

    public static partial class ImageExtensions
    {
        public static MemoryStream ToMemoryStream(this Image image, ImageFormat format)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            if (format == null)
                throw new ArgumentNullException("format");

            MemoryStream stream = new MemoryStream();           
            image.Save(stream, format);
            return stream;
        }
    }
}
